Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 11, 2026

Implements comprehensive logging of all RPC messages (requests/responses) sent and received by the gateway, with privacy preservation, server attribution, and payload previews.

Implementation

New RPC Logger (internal/logger/rpc_logger.go)

  • Dual logging to text (mcp-gateway.log) and markdown (gateway.md) formats
  • Privacy-preserving: reuses existing sanitizeSecrets() to filter tokens, API keys, passwords
  • Payload preview: 10KB for text logs, 120 characters for markdown logs
  • Metadata captured: direction (IN/OUT), server ID, method, payload size
  • Concise format: Short, intuitive symbols and minimal verbosity for quick scanning

Integration Points

  • internal/mcp/connection.go: New SendRequestWithServerID() method logs all backend communication
  • internal/server/*.go: Updated callers to pass server ID for attribution

Log Format

Text (concise, scannable, up to 10KB payload):

github→tools/list 58b {"jsonrpc":"2.0"...}
github←resp 284b err:timeout {"result":{...}}

Markdown (inline, intuitive, up to 120 chars payload):

**github**`tools/list` `{"jsonrpc":"2.0"...}`
**github**←resp ⚠️`timeout` `{"result":{...}}`

Format Features:

  • Directional arrows: (outbound), (inbound)
  • Concise size notation: 58b
  • Server attribution: **server**
  • Inline payload preview: 10KB for text logs, 120 chars for markdown
  • Error indicators: err:message (text), ⚠️ (markdown)

Testing

  • 10 new unit tests covering truncation (10KB text, 120 chars markdown), sanitization, formatting, concurrency
  • All existing tests pass (600+ unit, integration)
Original prompt

Add logging of every rpc message sent and received in the text and markdown logs.

  • privacy preserving
  • associate to server
  • message type, payload size or essential field
  • first few 120 characters of payload (filter secrets)

In markdown, always attribute messages to server


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 11, 2026 17:39
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add logging for all RPC messages in text and markdown logs Add RPC message logging with privacy-preserving payload preview Jan 11, 2026
Copilot AI requested a review from pelikhan January 11, 2026 17:43
@pelikhan
Copy link
Collaborator

@copilot make the format short, intuitive and less verbose . Assume the user will learn.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 11, 2026

@copilot make the format short, intuitive and less verbose . Assume the user will learn.

Updated format to be shorter and more intuitive (commit 6be2a4b):

Text: github→tools/list 58b {"jsonrpc":"2.0"...}
Markdown: **github**→\tools/list` `{"jsonrpc":"2.0"...}``

  • Removed verbose labels ([OUT], server=, method=)
  • Use arrows: (out), (in)
  • Concise size: 58b vs size=58
  • Inline payload (no code blocks)

@pelikhan
Copy link
Collaborator

the text format can inline the first 10kb of the json message payload

@pelikhan
Copy link
Collaborator

@copilot the text format can inline the first 10kb of the json message payload

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 11, 2026

@copilot the text format can inline the first 10kb of the json message payload

Increased text log payload preview to 10KB (commit d46148b). Markdown logs remain at 120 chars for readability.

Text format now inlines up to 10,240 bytes of sanitized JSON
Markdown format keeps 120 char limit for human readability

@pelikhan pelikhan marked this pull request as ready for review January 11, 2026 18:05
@pelikhan pelikhan merged commit 3778f0b into main Jan 11, 2026
3 checks passed
@pelikhan pelikhan deleted the copilot/add-logging-rpc-messages branch January 11, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants